/*----------------------------------------------------------------------------
Owner(s): Shane Whitfield
$Copyright: $
$Id: $
----------------------------------------------------------------------------*/

#include "timermgr.h"
#include <string.h>
#include "engine.h"

/*--------------------------------------------------------------------------*/

CTimeMgr::CTimeMgr() : super("TimeMgr")
{
	m_state = EState_Running;
	
	m_dt = 0.0f;
	m_t = 0.0f;
	m_systemDt = 0.0f;
	m_systemT = 0.0f;
	m_pausedForSystemMessage = false;
}

void CTimeMgr::On_Command(const char* i_command, const char* i_parameters)
{
	if (!strcmp(i_command, "pause"))
	{
		Pause();
	}
	else if (!strcmp(i_command, "run"))
	{
		Run();
	}
}

void CTimeMgr::setState(EState i_state)
{
	if (i_state == m_state)
	{
		return;
	}
	
	m_state = i_state;
}

void CTimeMgr::Update(float i_dt)
{
	//i_dt is in ms
	
	//if a system message is always up... then pause the game
	// but if the system message is now showing anymore and we paused it.. make it running again.
	if (g_engine.IsSystemMessageShowing() && (m_state != EState_Paused))
	{
		setState(EState_Paused); 
		m_pausedForSystemMessage = true;
	}
	else if (!g_engine.IsSystemMessageShowing() && m_pausedForSystemMessage)
	{
		setState(EState_Running); 
		m_pausedForSystemMessage = false;
	}

	if (m_state == EState_Running)
	{
		m_dt = i_dt;
		m_t += i_dt;
	}
	else
	{
		m_dt = 0.0f;
	}
	
	m_systemDt = i_dt;
	m_systemT += i_dt;
}
/*-----------------------------------EOF!-----------------------------------*/ 